home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9711 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,comp.unix.aix
  4. Subject: Re: Help: write() to a socket hangs unless there's a newline
  5. Followup-To: comp.unix.aix,comp.unix.programmer
  6. Date: Tue, 12 Mar 96 19:02:58 GMT
  7. Organization: none
  8. Message-ID: <826657378snz@genesis.demon.co.uk>
  9. References: <5r68cae4wm.fsf@ritz.mordor.com>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <5r68cae4wm.fsf@ritz.mordor.com>
  16.            benjamin@ritz.mordor.com "Joseph Thomas" writes:
  17.  
  18. >I realize this is not a direct C question, but it does have to do with
  19. >streams, and I tend to think the expertise to answer this is here:
  20.  
  21. You're more likely to find the expertise in the appropriate newsgroup e.g.
  22. comp.unix.programmer. (comp.unix.aix readers please bear with me, this is
  23. directed at the comp.lang.c cross-post).
  24.  
  25. >I've opened a socket, and connected it to another.  I'm using write() to
  26. >send a message through, ex:
  27.  
  28. Neither sockets not Unix system calls such as write() are part of the
  29. C language so it is not appropriate to discuss them in comp.lang.c.
  30. There is nothing here that relates to C streams.
  31.  
  32. >write(sock_fd, "Hello world", strlen("Hello world"));
  33. >
  34. >When I do this, the message gets through to the other socket, but the
  35. >write() call hangs in the process that executed it.
  36. >
  37. >However, if I send it as: 
  38. >
  39. >write(sock_fd, "Hello world\n", strlen("Hello world\n"));
  40. >
  41. >It doesn't hang, but I have a newline I don't want at the other end.
  42.  
  43. That looks very odd. Make sure write() is prototyped in your system (and
  44. you are including such a prototype) or you are forcing the 3rd argument
  45. to a suitable type.
  46.  
  47. >In addition, for some reason, between the next write()-->read() that I
  48. >try, I read() two null strings before I actually get the next
  49. >message (this may be something particular to sockets?)
  50.  
  51. More evidence that the length (3rd) argument is not being passed correctly.
  52.  
  53. >I've tried using fflush(sock_fd),
  54.  
  55. Evidence that the function declarations aren't prototyped or that you aren't
  56. including the relevant header files. Prototypes would have caught the fact
  57. that this illegally passes a sock_fd value (probably int) to a standard
  58. function that requires a FILE * value. fflush() flushes the buffering within
  59. the C standard library which doesn't exist for file descriptors.
  60.  
  61. Maybe comp.lang.aix readers can shed more light on this. Please note
  62. follow-ups directed away from comp.lang.c.
  63.  
  64. >but that causes a broken pipe for
  65. >some reason.  Can anyone say what gives here?
  66.  
  67. fflush(integer value) results in undefined behaviour - anything can happen.
  68.  
  69. -- 
  70. -----------------------------------------
  71. Lawrence Kirby | fred@genesis.demon.co.uk
  72. Wilts, England | 70734.126@compuserve.com
  73. -----------------------------------------
  74.